home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nibble Magazine
/
nib15.dsk
/
NIBBLE PROGRAMMER.bas
< prev
next >
Wrap
BASIC Source File
|
2023-02-26
|
12KB
|
434 lines
10 REM **********************
11 REM * NIBBLE PROGRAMMER *
12 REM * BY PAUL M. HYMAN *
13 REM * COPYRIGHT (C) 1983 *
14 REM * BY MICROSPARC, INC *
15 REM * LINCOLN, MA. 01773 *
16 REM **********************
100 HOME
105 HIMEM: 37799
110 ER = 0
115 POKE 222,0: POKE 216,0
120 ONERR GOTO 810
130 REM CONSTANT 1
140 C1 = 1
200 HTAB 12: PRINT "NIBBLE PROGRAMMER": PRINT : PRINT "** COPYRIGHT 1983 BY MICROSPARC, INC. **"
500 D$ = CHR$(4)
502 PRINT D$;"OPEN STB.P1.TMP"
504 PRINT D$;"DELETE STB.P1.TMP"
506 PRINT D$;"OPEN STB.P2.TMP"
508 PRINT D$;"DELETE STB.P2.TMP"
510 PRINT D$;"BLOAD NL.BIN"
600 VTAB 20
610 HOME
700 INPUT "INPUT FILE-";FF$
800 PRINT D$;"OPEN ";FF$
805 GOTO 2700
810 REM ***** ERROR ROUTINE
820 X = PEEK(222)
830 IF X = 5 GOTO 900
840 PRINT D$;"CLOSE"
850 PRINT "APPLESOFT/DOS ERROR ";X;" AT LINE "; PEEK(218) + PEEK(219) *256
860 END
900 PRINT D$;"CLOSE ";FF$
910 INPUT "MORE FILES? (Y/N) ";X$
920 IF X$ = "N" THEN PRINT "YOU SHOULD PUT A QUIT AT THE END OF THE LAST FILE": GOTO 7710
940 INPUT "FILE NAME - ";FF$
950 PRINT D$;"OPEN";FF$
960 GOTO 6800
1100 REM *** SUBR TO WRITE TO FILE ****
1200 REM
1300 PRINT D$;"WRITE STB.P1.TMP"
1400 PRINT LN;GG$
1500 PRINT D$
1700 LN = LN +10
1800 RETURN
2700 PRINT D$;"OPEN STB.P1.TMP"
3000 REM THE 4 DIM'S ARE THE SYMBOL TABLE
3100 REM NUMBER OF LABELS
3200 NL = 100
3300 REM NAME FIELD
3400 DIM L$(NL)
3500 REM LINE#
3600 DIM LI%(NL)
4100 REM LABLE TABLE INDEX
4200 LX = 0
4300 LN = 10
4400 REM WHILE STACK
4500 DIM WS%(10)
4600 REM WHILE LABLE STACK
4700 DIM WL$(10)
4800 REM INIT WHILE STACK PTR
4900 WP = -1
5000 REM INTERNAL LABEL TABLE
5010 DIM IL%(200)
5100 REM LOOP STACK
5200 DIM LS%(10)
5300 DIM LOOPLABELSTACK
5400 DIM LL$(10)
5500 REM INIT LOOP STACK PTR
5600 LP = -1
5700 REM INITIAL LABEL NUMBER
5800 L1 = 0
5900 REM *** THE IF STACK
6000 DIM I1$(10)
6100 REM THE IF-SEG STACK
6200 DIM I2$(10)
6300 REM IP IS PTR TO IF STACK
6400 IP = -1
6500 REM IQ IS PTR TO IF-SEG STACK
6600 IQ = -1
6800 A$ = ""
6900 PRINT D$;"READ ";FF$
6910 X = PEEK(49385)
7000 POKE 37800,1
7010 CALL 37802,A$
7020 IF LEN(A$) = 0 GOTO 7010
7030 IF ASC(A$) = 13 GOTO 7010
7100 AL$ = LEFT$(A$,1)
7200 IF AL$ = "*" GOTO 6800
7300 IF AL$ > = "0" AND AL$ < = "9" THEN FLASH : PRINT "LINE NUMBERS NOT ALLOWED": NORMAL :ER = ER +1: GOTO 6800
7500 X = PEEK(37801)
7510 IF X = 0 GOTO 24100
7520 ON X GOTO 15700,16900,17700,19100,18400,19610,23210,21000,22405,7710,23930,8700,11410,11410
7700 STOP
7710 GG$ = "END"
7720 GOSUB 1300
7730 PRINT D$;"WRITE STB.P1.TMP"
7740 PRINT "QUIT"
7800 GOSUB 26300
8000 PRINT D$;"CLOSE STB.P1.TMP"
8100 PRINT D$;"CLOSE ";FF$
8120 IF ER = 0 GOTO 27600
8130 PRINT ER;" ERRORS DETECTED"
8140 PRINT D$;"DELETE STB.P1.TMP"
8150 END
8300 REM
8400 REM ******* LABEL *****
8500 REM
8700 LA = LEN(A$)
8900 A$ = RIGHT$(A$,LA -1)
8910 SF$ = A$
8920 GOSUB 13900
9000 GOSUB 9300
9100 GOTO 6800
9200 REM
9300 REM **** LABEL DEF. SUBR *****
9310 IF LEFT$(A$,1) = "." GOTO 11110
9400 IF LX = 0 GOTO 10700
9500 FOR I -0 TO LX -1
9600 IF L$(I) < >A$ GOTO 10400
9800 PRINT L$(I);"---> DOUBLE DEFINITION"
9810 ER = ER +1
9900 I = 1000
10400 NEXT
10500 IF I = 1001 THEN RETURN : REM DBL DEF ERR
10700 L$(LX) = A$
10800 LI%(LX) = LN
10900 LX = LX +1
11100 RETURN
11110 A$ = RIGHT$(A$, LEN(A$) -1)
11120 IL%( VAL(A$)) = LN
11130 RETURN
11200 REM ***** GOTO ****
11300 REM
11410 GOSUB 11800
11420 GG$ = A$
11500 GOSUB 1200
11600 GOTO 6800
11700 REM ** SUBR TO PROC GOTOS **
11800 REM
11810 LM = 0
11830 SF$ = "GOTO"
11900 REM SEARCH LINE FOR GOTO
12000 GOSUB 24600
12100 REM LM=0 MEANS NO GOTO
12200 IF LM < >0 GOTO 12400
12210 SF$ = "GOSUB"
12220 GOSUB 24600
12230 IF LM = 0 THEN RETURN
12400 LM = LM +3
12500 REM EXTRACT LABEL AFTER GOTO
12600 GL$ = RIGHT$(A$,LA -LM)
12700 SF$ = GL$
12800 GOSUB 13800
13700 RETURN
13800 REM ****** SUBR TO CHECK LABEL VALIDITY ***
13900 IF LEFT$(SF$,1) > = "A" AND LEFT$(SF$,1) < = "Z" THEN RETURN
14000 ER = ER +1
14100 FLASG: PRINT SF$;"-ILLEGAL LABEL": NORMAL
14200 RETURN
15400 REM
15500 REM ****** WHILE *******
15600 REM
15700 R$ = RIGHT$(A$, LEN(A$) -5)
15800 GG$ = "IF" +R$ +"GOTO" + STR$(LN +20)
15900 GOSUB 1200
16000 A$ = "GOTO." + STR$(L1)
16100 GG$ = A$: GOSUB 1200
16200 WP = WP +1
16300 WS%(WP) = LN -20
16400 WL$(WP) = "." + STR$(L1)
16500 L1 = L1 +1
16600 GOTO 6800
16800 REM ************ ENDWHILE ********
16900 IF WP > = 0 GOTO 16990
16910 FLASH
16920 PRINT "NO MATCHING WHILE STATEMENT"
16930 NORMAL
16940 ER = ER +1
16950 GOTO 6800
16990 GG$ = "GOTO" + STR$(WS%(WP))
17000 GOSUB 1200
17100 A$ = WL$(WP)
17200 WP = WP -1
17300 REM GOTO LABEL DEF ROUTINE
17400 GOSUB 9300
17410 GOTO 6800
17600 REM ********* LOOP ***********
17700 LP = LP +1
17800 LS%(LP) = LN
17900 LL$(LP) = "." + STR$(L1)
17910 L1 = L1 +1
18000 LM = LM +1
18100 GOTO 6800
18300 REM *********** ENDLOOP ********
18400 IF LP > = 0 GOTO 18490
18410 FLASH : PRINT "NO MATCHING LOOP"
18420 NORMAL
18430 ER = ER +1
18440 GOTO 6800
18490 GG$ = "GOTO" + STR$(LS%(LP))
18500 GOSUB 1200
18600 A$ = LL$(LP)
18700 LP = LP -1
18800 GOSUB 9300
18810 GOTO 6800
19000 REM ************ EXIT LOOP ******
19100 R$ = RIGHT$(A$, LEN(A$) -8)
19110 IF LP > = 0 GOTO 19200
19120 FLASH
19130 PRINT "NO MATCHING LOOP"
19140 NORMAL
19150 ER = ER +1
19160 GOTO 6800
19200 A$ = R$ +"GOTO" +LL$(LP)
19300 GG$ = A$: GOSUB 1200
19400 GOTO 6800
19600 REM ********* IF *********
19610 SF$ = "THEN"
19620 GOSUB 24600
19625 REM IF "THEN" EXISTS, NOTHING CAN FOLLOW IT
19630 IF LM = LEN(A$) -3 GOTO 19700
19635 IF LM >0 GOTO 19680
19637 REM NO GOTO ALLOWED HERE
19640 SF$ = "GOTO"
19650 GOSUB 24600
19660 IF LM = 0 GOTO 19700
19680 FLASH : PRINT "ILLEGAL IF STATEMENT":ER = ER +1: NORMAL
19690 PRINT ".......";SF$;" AT CHAR ";LM
19700 GG$ = A$ +"GOTO" + STR$(LN +20)
19800 GOSUB 1200
19900 IQ = IQ +1
20000 IP = IP +1
20100 I1$(IP) = "." + STR$(L1)
20200 L1 = L1 +1
20300 I2$(IQ) = "." + STR$(L1)
20400 L1 = L1 +1
20500 A$ = "GOTO" +I2$(IQ)
20600 GG$ = A$: GOSUB 1200
20700 GOTO 6800
20900 REM ********* ELSE IF *******
21000 X$ = A$
21005 IF IP <0 OR IQ <0 GOTO 23520
21010 A$ = "GOTO" +I1$(IP)
21020 GG$ = A$: GOSUB 1200
21100 A$ = I2$(IQ)
21200 IQ = IQ -1
21300 REM DEFINE LABEL
21400 GOSUB 9300
21500 GG$ = RIGHT$(X$, LEN(X$) -4) +"GOTO" + STR$(LN +20)
21600 GOSUB 1200
21700 IQ = IQ +1
21800 I2$(IQ) = "." + STR$(L1)
21900 L1 = L1 +1
22000 A$ = "GOTO" +I2$(IQ)
22100 GG$ = A$: GOSUB 1200
22200 GOTO 6800
22400 REM ****** ELSE *****
22405 IF IP <0 OR IQ <0 GOTO 23520
22410 A$ = "GOTO" +I1$(IP)
22420 GG$ = A$: GOSUB 1200
22500 A$ = I2$(IQ)
22600 REM PUT DUMMY LABL ON STACK FOR ENDIF
22700 I2$(IQ) = "." + STR$(L1)
22800 L1 = L1 +1
22900 GOSUB 9300
23000 GOTO 6800
23200 REM ******* ENDIF *****
23210 IF IQ <0 GOTO 23520
23300 A$ = I2$(IQ)
23400 IQ = IQ -1
23500 GOSUB 9300
23510 IF IP > = 0 GOTO 23600
23520 FLASH : PRINT "NO MATCHING IF STATEMENT": NORMAL
23530 ER = ER +1
23540 GOTO 6800
23600 A$ = I1$(IP)
23700 IP = IP -1
23800 GOSUB 9300
23900 GOTO 6800
23920 REM ************ ON ***********
23930 IF MID$ (A$,3,2) = "ERR" GOTO 24040
23940 SF$ = "GOTO"
23950 GOSUB 24600
23960 IF LM >0 THEN J = LM +4: GOTO 23990
23970 SF$ = "GOSUB": GOSUB 23600
23980 IF LM >0 THEN J = LM +5: GOTO 23990
23985 FLASH : PRINT "ILLEGAL ON STMNT":ER = ER +1: NORMAL : GOTO 6800
23990 GOSUB 26210
24000 GOSUB 13800
24010 IF LL = 0 GOTO 23990
24015 GG$ = A$
24020 GOSUB 1200
24030 GOTO 6800
24035 REM ******* ONERR *******
24040 GOSUB 11700
24050 GOSUB 1200
24060 GOTO 6800
24070 REM ******* STANDARD BASIC LINE *******
24100 GG$ = A$
24200 GOSUB 1200
24300 GOTO 6800
24400 REM *****************
24500 REM SUB TO SEARCH FOR SF$ IN A$
24600 LS = LEN(SF$)
24700 LM = 1
24800 LA = LEN(A$)
24805 REM CHECK FOR QUOTE
24810 IF MID$ (A$,LM,1) < > CHR$(34) GOTO 24900
24820 REM SCAN FOR MATCHING QUOTE
24830 LM = LM +C1
24860 IF MID$ (A$,LM,C1) < > CHR$(34) GOTO 24830
24870 LM = LM +1
24900 IF MID$ (A$,LM,LS) = SF$ GOTO 25300
25000 LM = LM +1
25100 IF LM <LA -LS GOTO 24810
25200 LM = 0
25300 RETURN
25400 REM ************
25500 REM **SUBR TO SEARCH LABLE TABLE
25600 IF LEFT$(SF$,1) < >"." GOTO 25700
25610 SF$ = RIGHT$(SF$, LEN(SF$) -1)
25620 IZ = IL%( VAL(SF$))
25630 RETURN
25700 IF LX = 0 THEN IZ = -1: RETURN
25800 I = -1
25900 FOR D = 0 TO 1
26000 I = I +1
26010 D = L$(I) = SF$ OR I = LX
26100 NEXT
26110 IZ = I
26120 IF I = LX THEN IZ = -1
26130 IF IZ < > -1 THEN IZ = LI%(IZ)
26200 RETURN
26210 REM ****** SUBR TO EXTRACT ON...GOTO LABELS
26220 REM **** J POINTS TO LABEL
26230 LB$ = ""
26240 LL = 0
26250 IF J > LEN(A$) THEN LL = 1: RETURN
26260 X$ = MID$ (A$,J,1)
26270 IF X$ = "," THEN J = J +1: RETURN
26280 LB$ = LB$ +X$
26290 J = J +1: GOTO 26250
26300 PRINT D$
26400 PRINT "NUMBER OF LABELS=";LX
27000 IF WP = -1 GOTO 27410
27100 FOR I = 0 TO WP -1
27190 FLASH
27200 PRINT "UNTERMINATED WHILE AT STMT ";
27300 PRINT WS%(I)
27310 ER = ER +1
27320 NORMAL
27400 NEXT
27410 IF LP <0 GOTO 27420
27415 FLASH : PRINT LP +1;"UNTERMINATED LOOP STATEMENT(S)":ER = ER +1
27420 IF IP <0 AND IQ <0 GOTO 27430
27425 FLASH : PRINT "UNTERMINATED IF STATEMENT":ER = ER +1
27430 NORMAL
27440 PRINT "------------- END PASS 1 ------------"
27500 RETURN
27600 PRINT D$;"OPEN STB.P2.TMP"
27700 PRINT D$;"OPEN STB.P1.TMP"
27800 PRINT D$;"WRITE STB.P2.TMP"
27900 PRINT "NEW"
28000 PRINT D$;"READ STB.P1.TMP"
28010 X = PEEK(49385)
28100 POKE 37800,0
28110 CALL 37802,A$
28200 IF PEEK(37801) < >10 GOTO 29000
28210 IF ER = 0 GOTO 28300
28220 PRINT ER;" ERRORS DETECTED"
28230 PRINT D$;"CLOSE"
28240 PRINT D$;"DELETE STB.P1.TMP"
28250 PRINT D$;"DELETE STB.P2.TMP"
28260 END
28300 PRINT D$;"WRITE STB.P2.TMP"
28310 PRINT "TEXT"
28315 PRINT "HOME"
28320 PRINT "PRINT"; CHR$(34);"PROGRAM IS NOW LOADED"; CHR$(34)
28400 PRINT "DELETE STB.P2.TMP"
28500 PRINT D$;"CLOSE STB.P1.TMP"
28600 PRINT D$;"CLOSE STB.P2.TMP"
28700 PRINT D$;"DELETE STB.P1.TMP"
28710 HOME : VTAB 10: HTAB 10: PRINT "LOADING"
28720 VTAB 23
28730 POKE 34,23
28800 PRINT D$;"EXEC STB.P2.TMP"
28900 END
29000 REM
29010 J = 1
29020 IF MID$ (A$,J,1) < = "9" THEN J = J +1: GOTO 29020
29030 SF$ = MID$ (A$,J,2)
29050 IF SF$ < >"IF" AND SF$ < >"GO" AND SF$ < >"ON" GOTO 30300
29100 SF$ = "GOTO"
29200 GOSUB 24600
29300 IF LM >0 THEN GL = LM +4: GOTO 29710
29400 SF$ = "GOSUB"
29500 GOSUB 24600
29600 IF LM = 0 GOTO 30300
29700 GL = LM +5
29710 IF MID$ (A$,J,2) = "ON" AND MID$ (A$,J,5) < >"ONERR" GOTO 30700
29800 GL$ = RIGHT$(A$, LEN(A$) -GL +1)
29805 IF LEFT$(GL$,1) > = "0" AND LEFT$(GL$,1) < = "9" GOTO 30300
29807 SF$ = GL$
29810 GOSUB 25500
29900 IF IZ = -1 GOTO 30217
30100 A$ = LEFT$(A$,GL -1) + STR$(IZ)
30210 GOTO 30300
30217 PRINT D$: FLASH
30220 PRINT "----->";GL$;" UNDEFINED"
30225 ER = ER +1
30230 NORMAL
30300 PRINT D$;"WRITE STB.P2.TMP"
30400 PRINT A$
30410 V = VAL(A$)
30420 IF INT(V/100) *100 = V THEN PRINT "X=PEEK(49385)"
30500 PRINT D$: PRINT A$
30600 GOTO 28000
30700 REM ** PROCESS ON STATEMENT
30800 GL$ = LEFT$(A$,GL -1)
31000 J = GL
31100 GOSUB 26210
31200 SF$ = LB$
31300 GOSUB 25700
31400 IF IZ > = 0 GOTO 31500
31410 ER = ER +1
31420 FLASH : PRINT SF$;" UNDEFINED"
31430 NORMAL
31440 IF LL = 0 GOTO 31100
31450 GOTO 30300
31500 GL$ = GL$ + STR$(IZ)
31600 IF LL = 0 THEN GL$ = GL$ +",": GOTO 31100
31700 A$ = GL$
31800 GOTO 30300